#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<stdlib.h>

//int judge(char* s, int left, int right)
//{
//    while (left < right)
//    {
//        if (s[left] != s[right])
//        {
//            return false;
//        }
//        left++;
//        right--;
//    }
//    return true;
//}
//bool validPalindrome(char* s) {
//    int len = strlen(s);
//    int left = 0;
//    int right = len-1;
//    while (left < right)
//    {
//        if (s[left] != s[right])
//        {
//            return judge(s, left + 1, right) || judge(s, left, right - 1);
//        }
//        left++;
//        right--;
//    }
//    return true;
//}
//
//int main()
//{
//    char arr[] = { "deeee" };
//    printf("%d ",validPalindrome(arr));
//	return 0;
//}

char* shortestCompletingWord(char* licensePlate, char** words, int wordsSize) {
    int arr1[26] = { 0 };
    int arr2[26] = { 0 };
    int i = 0;
    while (licensePlate[i] != '\0')
    {
        if (licensePlate[i] >= 'a' && licensePlate[i] <= 'z')
        {
            arr1[licensePlate[i] - 'a']++;
        }
        if (licensePlate[i] >= 'A' && licensePlate[i] <= 'Z')
        {
            arr1[licensePlate[i] - 'A']++;
        }
        i++;
    }
    int minlen = 1000,pos = 0;
    for (i = 0; i < wordsSize; i++)
    {
        int j = 0;
        int len = 0;
        while (words[i][j] != '\0')
        {
            arr2[words[i][j] - 'a']++;
            len++;
            j++;
        }
        int flag = 1;
        for (int z = 0; z < 26; z++)
        {
            if (arr1[z] > arr2[z])
            {
                flag = 0;
                break;
            }
        }
        if (flag)
        {
            if (len < minlen)
            {
                pos = i;
                minlen = len;
            }
        }
        memset(arr2, 0, sizeof(int) * 26);
    }
    return words[pos];
}


int main()
{
    char arr[] = { "1s3 456" };
    char** words = (char*)malloc(sizeof(char*) * 4);
    for (int i = 0; i < 4; i++)
    {
        words[i] = (char*)malloc(sizeof(char) * 8);
    }
    words[0] = "looks";
    words[1] = "pest";
    words[2] = "stew";
    words[3] = "show";
    printf("%s ",shortestCompletingWord(arr, words, 4));
    return 0;
}